package demo1;

import java.util.Arrays;

public class Test {
    public static void main1(String[] args) {
        Person[] people = new Person[3];

        people[0] = new Person("zhangsan",3,90.29);
        people[1] = new Person("lisi",10,95.99);
        people[2] = new Person("wangwu",8,80.1);

        Arrays.sort(people);//里面的元素都是自定义类型，这些类型都是可以比较的，需要实现Comparable接口！
        System.out.println(Arrays.toString(people));
        System.out.println("===========");
        int[] array = {1,4,2,9,7,0};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));

    }

    public static void bubbleSort(Comparable[] comparables){
        for(int i = 0; i < comparables.length - 1; i++){
            for (int j = 0; j < comparables.length - 1 - i; j++){
                if(comparables[j].compareTo(comparables[j+1]) > 0){
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
        Person[] people = new Person[3];
        people[0] = new Person("zhangsan",3,90.29);
        people[1] = new Person("lisi",10,95.99);
        people[2] = new Person("wangwu",8,80.1);

        bubbleSort(people);
        System.out.println(Arrays.toString(people));

    }
}
